import requests
import pymysql
import pandas as pd
import json
import threadpool
import re
import time
import parsel
import datetime


class Load:
    def __init__(self):
        self.conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                                    database='sunway_db', charset='utf8')
        self.cursor = self.conn.cursor()

        self.list1 = []

    def mysql_one(self, deliveredDate, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujian,
                  remark,
                  mysql_name):  # 四个参数的mysql
        conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                               database='sunway_db', charset='utf8')
        cursor = conn.cursor()
        newtime = time.strftime('%Y-%m-%d %H:%M:%S')
        cursor.execute(
            "REPLACE into {} set newtime=%s,deliveredDate=%s,Primary_key=%s,times=%s,title=%s,describes=%s,Tracking_number=%s,warehouse_sku=%s,zhujian=%s,remark=%s".format(
                mysql_name),
            [newtime, deliveredDate, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujian,
             remark])

        conn.commit()

    def mysql_two(self, isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku,pIds, zhujian,remark,mysql_name):  # 五个参数的MySQL
        conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                               database='sunway_db', charset='utf8')
        cursor = conn.cursor()
        newtime = time.strftime('%Y-%m-%d %H:%M:%S')
        cursor.execute(
            "REPLACE into {} set newtime=%s,isok=%s,Primary_key=%s,times=%s,title=%s,describes=%s,Tracking_number=%s,warehouse_sku=%s,pIds=%s,zhujian=%s,remark=%s".format(
                mysql_name),
            [newtime, isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, pIds, zhujian,
             remark])

        conn.commit()

    def mysql_three(self, isok, Primary_key, times, title, Tracking_number, warehouse_sku, zhujian, remark,
                    mysql_name):  # 三个参数的MySQL
        newtime = time.strftime('%Y-%m-%d %H:%M:%S')
        conn = pymysql.connect(host='192.168.2.205', port=3306, user='jinhuitao', password='jinhuitao_123456',
                               database='sunway_db', charset='utf8')
        cursor = conn.cursor()
        cursor.execute(
            "REPLACE into {} set newtime=%s,isok=%s,Primary_key=%s,times=%s,title=%s,Tracking_number=%s,warehouse_sku=%s,zhujian=%s,remark=%s".format(
                mysql_name),
            [newtime, isok, Primary_key, times, title, Tracking_number, warehouse_sku, zhujian, remark])

        conn.commit()

    def return_mysql(self):  # 获取数据库中的跟踪号和运输方式
        datas = "select track_code,logistics_method,warehouse_sku,zhujian,fba_status from det_fba_first_shipment_product"
        a = pd.read_sql(datas, self.conn)
        track_code_all = a['track_code']
        logistics_method_all = a['logistics_method']
        warehouse_sku_all = a['warehouse_sku']
        zhujian_all = a['zhujian']
        fba_status = a['fba_status']
        list_all = []
        list_all_ = []
        for jj in range(len(track_code_all)):
            if str(track_code_all[jj]) != 'None' and track_code_all[jj] not in list_all_:
                list_all_.append(track_code_all[jj])
                all = str(track_code_all[jj]) + '我是你哥' + str(logistics_method_all[jj]) + '我是你哥' + str(
                    warehouse_sku_all[jj] + '我是你哥' + str(zhujian_all[jj]) + '我是你哥' + str(fba_status[jj]))
                list_all.append(all)
        return list_all

    def screening_load(self):  # 甄别物流方式  主函数
        list_ = self.return_mysql()
        task_pool = threadpool.ThreadPool(30)
        requests = threadpool.makeRequests(self.threading_thread, list_)
        for req in requests:
            task_pool.putRequest(req)
        task_pool.wait()

    def threading_thread(self, word):
        words = word.split('我是你哥')
        load = words[1]  # 运输方式
        load_show = words[0]  # 跟踪号
        load_sku = words[2]  # 仓库sku
        zhujian = words[3]  # 主键
        fba_status = words[4]  # 状态
        if fba_status not in ['-1']:
            if 'ups'.lower() in load.lower():
                try:
                    self.ups(load_show, load_sku, zhujian)
                except Exception as g:
                    times, title, describes, Tracking_number, warehouse_sku, zhujians, remark = '', '', '', load_show, load_sku, zhujian, '无数据'
                    Primary_key = zhujian + str(times) + title
                    isok = None
                    print('ups', times, title, describes, Tracking_number, warehouse_sku, zhujians, remark)
                    self.mysql_one(isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians,
                                   remark,
                                   mysql_name='load_ups')

            elif 'fedex'.lower() in load.lower():
                try:
                    self.fedex(load_show, load_sku, zhujian)
                except Exception as g:
                    times, title, describes, Tracking_number, warehouse_sku, zhujians, remark = '', '', '', load_show, load_sku, zhujian, '无数据'
                    Primary_key = zhujian + str(times) + title
                    isok = None
                    print('fedex', times, title, describes, Tracking_number, warehouse_sku, zhujians, remark)
                    self.mysql_one(isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians,
                                   remark,
                                   mysql_name='load_fedex')



            elif 'dhl'.lower() in load.lower():
                try:
                    time.sleep(1)
                    self.dhl(load_show, load_sku, zhujian)
                except Exception as g:
                    times, title, describes, Tracking_number, warehouse_sku, pIds, zhujians, remark = '', '', '', load_show, load_sku, '', zhujian, '无数据'
                    Primary_key = zhujian + str(times) + title
                    isok = None
                    print('dhl', times, title, describes, Tracking_number, pIds, zhujians, remark)
                    self.mysql_two(isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, pIds,
                                   zhujians, remark,
                                   mysql_name='load_dhl')
            elif '九方' in load.lower():
                # print(1111)
                try:
                    self.jiufang(load_show, load_sku, zhujian)
                except Exception as g:
                    times, title, Tracking_number, warehouse_sku, zhujians, remark = '', '', load_show, load_sku, zhujian, '无数据'
                    Primary_key = zhujian + str(times) + title
                    isok = None
                    print('九方', times, title, Tracking_number, warehouse_sku, zhujians, remark)
                    self.mysql_three(isok, Primary_key, times, title, Tracking_number, warehouse_sku, zhujians, remark,
                                     mysql_name='load_jiufang')

            elif 'aaf'.lower() in load.lower():
                try:
                    self.aff_1(load_show, load_sku, zhujian)
                except Exception as g:
                    times, title, describes, Tracking_number, warehouse_sku, zhujians, remark = '', '', '', load_show, load_sku, zhujian, '无数据'
                    Primary_key = zhujian + str(times) + title
                    isok = None
                    print('aff', times, title, describes, Tracking_number, warehouse_sku, zhujians,
                          remark)
                    self.mysql_one(isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians, remark, mysql_name='load_aff')


            else:
                print()


        else:
            print('iiii')

    def aff(self):
        cookie_Token_ = self.login_1()
        url = 'http://aafgzx.nextsls.com/wos/shipment/index?kw=GZBL2202029916&waybill_number=&service=&daterange=&created_daterange=&country=&name=&store_id='
        headers = {
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'Connection': 'keep-alive',
            'Cookie': '{}'.format(cookie_Token_[1]),
            'Host': 'aafgzx.nextsls.com',
            'Referer': 'http://aafgzx.nextsls.com/wos/shipment/index?status=picked',
            'Upgrade-Insecure-Requests': '1',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',

        }

        response = requests.get(url, headers=headers).text
        response_parsel = parsel.Selector(response)
        response_parsel_country = response_parsel.css(
            '#w0 > table > tbody > tr > td:nth-child(5)::text').extract_first()
        response_tbody = re.findall('<tbody>(.*?)</tbody>', response, re.S)[0]
        response_data_key = re.findall('data-key="(.*?)"', response_tbody)[0]
        return [cookie_Token_[0], cookie_Token_[1], response_data_key, response_parsel_country]

    def aff_1(self, load_show, load_sku, zhujian):
        times1 = int(time.time() * 1000)
        id_cookie_token = self.aff()
        url = 'http://aafgzx.nextsls.com/wos/shipment/show_traces?id={}&lmodal=1&_={}'.format(
            id_cookie_token[2], times1)
        headers = {
            'Accept': '*/*',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'Connection': 'keep-alive',
            'Cookie': '{}'.format(id_cookie_token[1]),
            'Host': 'aafgzx.nextsls.com',
            'Referer': 'http://aafgzx.nextsls.com/wos/shipment/index?status=delivered',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',
            'X-CSRF-Token': '{}'.format(id_cookie_token[0]),
            'X-Requested-With': 'XMLHttpRequest',
        }
        param = {
            'id': '{}'.format(id_cookie_token[2]),
            'lmodal': '1',
            '_': '{}'.format(times1)

        }
        response = requests.get(url, headers=headers, params=param).text
        response_parsel = parsel.Selector(response)
        response_parsel_ = response_parsel.css('#one-column > div')
        is_ok = True
        for response_parsel_div in response_parsel_:
            response_parsel_div_ = response_parsel_div.css('div > div.message-head.clearfix::text').get().strip()  # 时间
            response_parsel_div_span = response_parsel_div.css(
                'div > div.qa-message-content span::text').get().strip()  # 标题
            print(id_cookie_token[3], response_parsel_div_, response_parsel_div_span)
            times, title, describes, Tracking_number, warehouse_sku, zhujians, remark = response_parsel_div_, response_parsel_div_span,id_cookie_token[3], load_show, load_sku, zhujian, ''
            Primary_key = zhujians + str(times) + title
            if is_ok and response_parsel_div_span.split('，')[0] in ['DELIVERED','航班已抵达','航班已起飞','已下单','货物已交付','已清关放行','已发出']:
                isok = self.times_(title.split('，')[0], 'aff', times)
                self.mysql_one(isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians,
                               remark,
                               mysql_name='load_aff')
                is_ok = False
                print('aff:::',isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians,remark)
            else:
                isok_ = None
                self.mysql_one(isok_, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians,
                               remark,
                               mysql_name='load_aff')
                print('aff:::',isok_, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians,remark)

    def login_(self):
        url = 'http://aafgzx.nextsls.com/wos/login/'
        headers = {

            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'Cache-Control': 'max-age=0',
            'Connection': 'keep-alive',
            'Cookie': 'grid-view-pagesize=10',
            'Host': 'aafgzx.nextsls.com',
            'Referer': 'http://aafgzx.nextsls.com/wos/login/',
            'Upgrade-Insecure-Requests': '1',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',

        }
        response = requests.get(url, headers=headers)
        return [response.headers['Set-Cookie'], re.findall('<meta name="csrf-token" content="(.*)">', response.text)[0]]

    def login_1(self):
        cookie_Token = self.login_()
        url = 'http://aafgzx.nextsls.com/wos/login'
        headers = {

            'Accept': 'application/json, text/javascript, */*; q=0.01',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'Connection': 'keep-alive',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Cookie': '{}'.format(cookie_Token[0]),
            'Host': 'aafgzx.nextsls.com',
            'Origin': 'http://aafgzx.nextsls.com',
            'Referer': 'http://aafgzx.nextsls.com/wos/login/',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',
            'X-CSRF-Token': '{}'.format(cookie_Token[1]),
            'X-Requested-With': 'XMLHttpRequest',

        }

        data = {
            'username': '广州盛业',
            'password': '123456',
            'inajax': '1'
        }
        response = requests.post(url, headers=headers, data=data).headers
        cookie = '_csrf-parcelos-wos' + re.findall('_csrf-parcelos-wos(.*?);', cookie_Token[0])[
            0] + ';' + 'parcelos_wos=' + \
                 re.findall('parcelos_wos=(.*?);', response['Set-Cookie'])[0]
        return [cookie_Token[1], cookie]

    def jiufang(self, jiufang_load, warehouse_sku, zhujians):
        url = 'http://www.tofba.com:8081/seaair/waybills/listPage'
        headers = {
            'Accept': 'application/json, text/plain, */*',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'Authorization': 'eyJhbGciOiJIUzI1NiJ9.eyJyZWdpc3RlcmVkTW9iaWxlUGhvbmVOdW1iZXIiOiIxODAyODU2OTY0MCIsInN1YiI6IjM4NzgiLCJjdXN0b21lckxvZ2luTmFtZSI6IlNXRFpTVyIsImlzcyI6ImF1dGhvciIsImN1c3RvbWVyQ29kZSI6Iko0MjQ1IiwiaWQiOjM4NzgsImV4cCI6MTYyMTg0MzY0NiwiaWF0IjoxNjIxODQzNjQ2LCJqdGkiOiIyY2VjOTYwMC0yODI4LTRiMmQtODRmZS0yYTE1MTk2YjQwOTEiLCJjdXN0b21lck5hbWVTaG9ydCI6Iuebm-S4uueUteWtkOWVhuWKoSJ9.D4BRKMUuV5bf6JS6dkydn1-9Z0CjbOUbqppqhMviA8E',
            'Cache-Control': 'no-cache',
            'Content-Length': '209',
            'Content-Type': 'application/json; charset=UTF-8',
            'Host': 'www.tofba.com:8081',
            'Origin': 'http://tofba.com:8887',
            'Pragma': 'no-cache',
            'Proxy-Connection': 'keep-alive',
            'Referer': 'http://tofba.com:8887/',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'x-tofba-session-status': 'y',
        }
        parm = json.dumps(
            {"status": [0], "inStockChannel": "", "waybillNo": "{}".format(jiufang_load), "trackNumber": "",
             "referenceNo": "",
             "countryId": "", "declareNameCn": "", "sku": "", "dispatchAddressCode": "", "shipmentID": "",
             "pageSize": 20, "currentPage": 1})
        parm1 = json.dumps(
            {"status": [0], "inStockChannel": "", "waybillNo": "", "trackNumber": "",
             "referenceNo": "",
             "countryId": "", "declareNameCn": "", "sku": "", "dispatchAddressCode": "",
             "shipmentID": "{}".format(jiufang_load),
             "pageSize": 20, "currentPage": 1})
        if jiufang_load[:2] == 'ZX':
            res = requests.post(url, headers=headers, data=parm, timeout=10).json()
        else:
            res = requests.post(url, headers=headers, data=parm1, timeout=10).json()
        id = res['datas'][0]['id']
        self.jiufang_run(jiufang_load, id, warehouse_sku, zhujians)

    def jiufang_run(self, jiufang_load, id, warehouse_sku, zhujians):
        url = 'http://www.tofba.com:8081/seaair/waybills/initWaybillState?id={}'.format(id)
        headers = {
            'Host': 'www.tofba.com:8081',
            'Connection': 'keep-alive',
            'Content-Length': '0',
            'Pragma': 'no-cache',
            'Cache-Control': 'no-cache',
            'Accept': 'application/json, text/plain, */*',
            'x-tofba-session-status': 'y',
            'Authorization': 'eyJhbGciOiJIUzI1NiJ9.eyJyZWdpc3RlcmVkTW9iaWxlUGhvbmVOdW1iZXIiOiIxODAyODU2OTY0MCIsInN1YiI6IjM4NzgiLCJjdXN0b21lckxvZ2luTmFtZSI6IlNXRFpTVyIsImlzcyI6ImF1dGhvciIsImN1c3RvbWVyQ29kZSI6Iko0MjQ1IiwiaWQiOjM4NzgsImV4cCI6MTYyMTg0MzY0NiwiaWF0IjoxNjIxODQzNjQ2LCJqdGkiOiIyY2VjOTYwMC0yODI4LTRiMmQtODRmZS0yYTE1MTk2YjQwOTEiLCJjdXN0b21lck5hbWVTaG9ydCI6Iuebm-S4uueUteWtkOWVhuWKoSJ9.D4BRKMUuV5bf6JS6dkydn1-9Z0CjbOUbqppqhMviA8E',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'Origin': 'http://tofba.com:8887',
            'Referer': 'http://tofba.com:8887/',
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        }
        res = requests.post(url, headers=headers, timeout=10).json()
        is_ok = True
        for j in res['data'][::-1]:
            # print(j)
            times = j['operationDateTime']
            title = j['content']
            if ' ' not in str(times) and '-' in str(times):
                times = str(times) + ' 00:00:00'
            Tracking_number = jiufang_load
            remark = 'True'
            if title == '':
                remark = '无数据'
            Primary_key = zhujians + str(times) + title
            if is_ok and title in ['已签收','已提取','已到仓','已清关','已到港','已离港','已放行','已出库']:
                isok = self.times_(title, 'jiufang', times)
                self.mysql_three(isok, Primary_key, times, title, Tracking_number, warehouse_sku, zhujians, remark,
                                 mysql_name='load_jiufang')
                is_ok = False
                print('jiufang:::',isok, Primary_key, times, title, Tracking_number, warehouse_sku, zhujians, remark)
            else:
                isok_ = None
                self.mysql_three(isok_, Primary_key, times, title, Tracking_number, warehouse_sku, zhujians, remark,
                                 mysql_name='load_jiufang')
                print('jiufang:::',isok_, Primary_key, times, title, Tracking_number, warehouse_sku, zhujians, remark)

    def dhl(self, dhl_load, warehouse_sku, zhujians):
        params = {
            'trackingNumber': '7692947006',
            'service': 'express'
        }

        headers = {
            'Accept': 'application/json',
            'DHL-API-Key': 'UZdgzAWrQdTLNALnvAsjaCx2mXokCSC4'

        }

        url = 'https://api-eu.dhl.com/track/shipments?tracking&language=zh'

        res = requests.get(url, params=params, headers=headers).json()
        is_ok = True
        for i in res['shipments'][0]['events']:  #
            times = i['timestamp']
            title = i['description']
            describes = i['location']['address']['addressLocality']
            Tracking_number = dhl_load
            remark = 'True'
            if title == '':
                remark = '无数据'
            Primary_key = zhujians + str(times) + title
            try:
                pIds = ''
                for o in i['pieceIds']:
                    pIds = pIds + ',' + o
                if is_ok and title in ['已派送','快件已完成清關手續並從海關放行', '貨件已離開DHL設施 HONG KONG - HONG KONG SAR, CHINA',
                                       '貨件已離開DHL設施 GUANGZHOU - CHINA MAINLAND']:

                    isok = self.times_(title, 'dhl', times)
                    self.mysql_two(isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku,pIds, zhujians,remark,mysql_name='load_dhl')
                    is_ok = False
                    print('dhl:::',isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians,remark, pIds)
                else:
                    isok_ = None
                    self.mysql_two(isok_, Primary_key, times, title, describes, Tracking_number, warehouse_sku,pIds,zhujians,remark,mysql_name='load_dhl')
                    print('dhl:::',isok_, Primary_key, times, title, describes, Tracking_number, warehouse_sku,zhujians,remark, pIds)
            except KeyError as g:
                pIds = ''
                if is_ok and title in ['已派送','快件已完成清關手續並從海關放行', '貨件已離開DHL設施 HONG KONG - HONG KONG SAR, CHINA',
                                       '貨件已離開DHL設施 GUANGZHOU - CHINA MAINLAND']:

                    isok = self.times_(title, 'dhl', times)
                    self.mysql_two(isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku,pIds, zhujians,
                                   remark,
                                   mysql_name='load_dhl')
                    is_ok = False
                    print('dhl:::',isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians,remark, pIds)
                else:
                    isok_ = None
                    self.mysql_two(isok_, Primary_key, times, title, describes, Tracking_number, warehouse_sku,pIds,
                                   zhujians,
                                   remark,
                                   mysql_name='load_dhl')
                    print('dhl:::',isok_, Primary_key, times, title, describes, Tracking_number, warehouse_sku,zhujians,remark, pIds)

    def fedex(self, fedex_load, warehouse_sku, zhujians):
        url = 'https://www.fedex.com/trackingCal/track'
        headers = {
            'Host': 'www.fedex.com',
            # 'Content-Length': '459',
            'ADRUM': 'isAjax:true',
            'sec-ch-ua-mobile': '?0',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Origin': 'https://www.fedex.com',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Dest': 'empty',
            'Referer': 'https://www.fedex.com/zh-cn/home.html',
            'Accept-Encoding': 'gzip, deflate, br',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            # 'Cookie': 'fdx_cbid=305401236416412883752251160372821; fdx_redirect=zh-cn; isTablet=false; isMobile=false; isWireless=false; Rbt=f0; gdl-clientId=a5192140-b372-4268-a809-adbf1929f4f0; g_sref=(direct); at_check=true; _svtri=ecfb50e7-a67e-409d-8ec8-9fe70a7d53cb; AMCVS_1E22171B520E93BF0A490D44%40AdobeOrg=1; s_ecid=MCMID%7C54992833931412773701780827342782704044; s_cc=true; Nina-nina-fedex-session=%7B%22locale%22%3A%22zh_cn%22%2C%22lcstat%22%3Afalse%7D; SMIDENTITY=idV+qWJkCsdvnztPTVNdiKUjII1sBnA/UUQkhnGeCnPKBIj5QgNUBqkG8r2pgU9zjRlADcyw1UmLM7TUO66UIN5PRJnhpTBqUdEdIcvY7dfivHl5+oALxIO+RMgn3lo4ofj2KHZfcDGb0IQxeWco5VcObWOciOo8NPklIktSbNGQki+z0lySazsYvzAHXXWf1zyn/dfqwD4NDd0ayE7okv45CcjqLW0NSn3kwW8QGsGTssDIQhtiiZUCG1tHVhGCUs2SH/Hfc0aFm9eKkp5MJK8oTl+uw0Atu/kFPaL78dPveJM/MK4C2KJHQ1VYjEwapQkkM8/dKwPfCtS8jKFMib/GCO07OhJhbBhJGVbFhKhRaLF0q+4oYNEUQU+l4B5lIKuqBQ3DdLsILPdAM7ymJFTM1ClOh55q3JcgeJ+kcSgEjDM4+nib+V2pIYVScwH7mtZXowJdDgmrgPZBz6HBzjujl3sEk6cYM98xOiCAm/3sNVt4Q2q7tc0eIQaSiv0lj0dgPzr+tjtl6wejVZVVzsnknsafgBSS; g_stime=1641347636386; mbox=PC#0066215abac045968004549b45edf750.32_0#1704598260|session#a056fd3380174340b3b76e072d059358#1641355319; fdx_locale=zh_CN; setLink=%5B%5BB%5D%5D; PIM-SESSION-ID=NnrlMpgV8A6pP9Fq; siteDC=edc; AMCV_1E22171B520E93BF0A490D44%40AdobeOrg=359503849%7CMCIDTS%7C18997%7CMCMID%7C54992833931412773701780827342782704044%7CMCAAMLH-1641961234%7C11%7CMCAAMB-1641961234%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1641363634s%7CNONE%7CMCAID%7CNONE%7CvVersion%7C5.0.1; QSI_HistorySession=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641288402174%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641347639453%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620457%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620492%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641353460113%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353489994%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353490317%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750035%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750248%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493146%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493159%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513873%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513878%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627481%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627492%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435278%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435505; _abck=886CA23387E220405ABD0C026386EB2B~0~YAAQNtMuF/HyTA1+AQAAX07aKAcDnf87pUAcRv5zmjU2kQ0oXhZsjPj8XBEtQ2HRMj6Y3ArYRE6XguRUDTzuv998/pLGvbGj8/G2NGWbqdS1VyYSuojewjYahsZA4LBSDSeGd/g3nXNJVGN+jITDPXbwqSxgzZujI/hSsVryIvDzZiDLGyu9TsUt5+oeYdd1iFq48AO9kkNTSX74JtTqNYzTj1R8cYIHAJU852Hbu8uuwA/AFFPjJ5TNzgf5vCREOTlHSIT3jn/f9xqtfOsDjRLFlRxEIgXHHSGoKlmAefutQeUVFrVWbv8FFRSsOIpMNn4n8d7AbVDw/yfrvK06pWhGqOiVh4HaujMFULk9N0CdmNLZGydziWaw5qAkODTvZwEddqcKgPb24mB3GusyA/bEgq8NFSI=~-1~-1~-1; ak_bmsc=3B1B1730CEE2B3BD4A625885CA97688E~000000000000000000000000000000~YAAQNtMuF/LyTA1+AQAAX07aKA7ILM72JrXwkPz4UlwskAECbPUZrzeiBc73Y0XnTczADlyV8I7ZBNjOwOh3pycee5Eqv9CJA+/t8KTcV7Qn4K7sIG981Ue7FlNgxwqeHHBQqQ0DrXaRQD17/P178PbqSoiI1rkEZINZAPrjQq2+0pLT2P4TjdwHOGWv2Y62vrBQu9PdZgt5e2c963c56WwK/Cu/s81yaRcwJRJNVmBICBNv6O0MVRhx5EJakyJXIlmSVnGyiGewc8AFSry6T4on5ctGpjJ6NXXB5nDCFSf3uu48Y6QNeK9JTjyWFf5kVZxCKHjVX4sRKB4WAbKP7fGr0GV8ccS2wn3B70xNfTQcN5oSOY9ehdnkGH8=; bm_sz=517985989C7DCBD9291A9826FAF6116D~YAAQNtMuF/PyTA1+AQAAX07aKA6SuAtRC2A/7/bY+fClRzv5STq31ykGHSXbXGXd1fzIx8ljWb1wQsGD/SBsppBR//Zu0qOk0ipd5atx+JQ7uuheWCSezVzwKvIKBZQ1izhMHX+qdy/NdJmao/po9c3euMVOQYZAV7Lpyp2TVllMIeWstzKyKYlJ1YGmp30E0LNcQL7VAVePSGcN8YhBDukINN2gKLgqzHgmojygkofehh6+XsYt33TyG34EUv5YxbQgkSyHg1/lFTAzDw2hHMvS3TU8CXLOC7iqHKtaW7GALQ==~4339250~4535620; s_sess=%20setLink%3D%3B%20s_ppv%3Dfedex%252Fhero%25257Ctrack%252C88%252C47%252C2536%3B%20SC_LINKS%3Dfedex%252Ftrk-detailpage-managedelivery%255E%255E%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255Efedex%252Ftrk-detailpage-managedelivery%2520%257C%2520%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255E%3B; s_pers=%20s_vnum%3D1641398399999%2526vn%253D4%7C1641398399999%3B%20gpv_pageName%3Dfedex%252Ftrk-detailpage-managedelivery%7C1641364733138%3B%20s_invisit%3Dtrue%7C1641364733147%3B; s_sq=fedexglbl%3D%2526c.%2526a.%2526activitymap.%2526page%253Dfedex%25252Ftrk-detailpage-managedelivery%2526link%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526region%253Dcontainer%2526pageIDType%253D1%2526.activitymap%2526.a%2526.c%2526pid%253Dfedex%25252Ftrk-detailpage-managedelivery%2526pidt%253D1%2526oid%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526oidt%253D3%2526ot%253DSUBMIT; ADRUM=s=1641362944203&r=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3F476261820; xacc=CN; aemserver=PROD-P-dotcom-c0016056.prod.cloud.fedex.com; bm_mi=B8EFA7EDF504E14BEE716B87C33A72DB~6UYWZe8ZUe26CWEs8kvvIA7nSLBKORtdDvJCO4E3lMBNZdFCPDyVZ7HGBHJwqEEOrA+cMACq381mNxpNIyljJF+9c9yJiKYrkyHY7ENUjXPP1W6KFnyInYSCHS1bK002EXXUSVn3Vehau4qasIMjCfd5+qb+v7wJT1usYckYSWAnPTX09KdQAkVcZ88kiY91TdXtpe+8uMKEsLX+jRNvWsFdXgUjDlSLLVhw54T0x4ESgvunRyWpkxN2vyF6lmPpR6MYO5rw5fYlJV8qU8jkVmEd78RfzHEudi+FOxOvFUeJJbzizTU94g2TU2UZ5xnb; bm_sv=4D3E7302F82B4D249F1ADB99FB5C8029~OCgNA7VPxKgyF4fZtN9KLCu9cVEab2s+XJkyzoHuBV2QJB0LcXwRZchnjut5jaII4Ork5iPqpfawAp4vBKsLtQcofhgy0Nbh+VRekLhxpf+X8/r8KtNdM01iE7720huo0nftWA74rbz0ccdLsA4GdmsOpm5+S1dBsA3/mM1DMJk='.format(j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j)
        }
        parm1 = {
            'action': 'trackpackages',
            'data': json.dumps({"TrackPackagesRequest": {"appDeviceType": "DESKTOP", "appType": "WTRK",
                                                         "processingParameters": {}, "uniqueKey": "",
                                                         "supportCurrentLocation": True, "supportHTML": True,
                                                         "trackingInfoList": [{"trackNumberInfo": {
                                                             "trackingNumber": "{}".format(fedex_load),
                                                             "trackingQualifier": "",
                                                             "trackingCarrier": ""}}]}}),
            'format': 'json',
            'locale': 'zh_CN',
            'version': '1',

        }
        list_fedex = []

        res1 = requests.post(url, headers=headers, data=parm1, verify=False, timeout=10).json()
        number = res1['TrackPackagesResponse']['packageList'][0]['masterQualifier']  # 2459543000
        remark = 'True'
        list_fedex.append(fedex_load)
        is_ok = True
        for i in res1['TrackPackagesResponse']['packageList'][0]['scanEventList']:
            times = i['date'] + ' ' + i['time']
            title = i['status']
            describes = i['scanLocation']
            Tracking_number = fedex_load
            zhujian = zhujians

            if title == '':
                remark = '无数据'
            Primary_key = zhujians + str(times) + title
            if is_ok and title in ['已送达','国际货物放行 - 进口','已离开 FedEx 始发地服务站']:
                isok = self.times_(title, 'fedex', times)
                self.mysql_one(isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujian,
                               remark,
                               mysql_name='load_fedex')
                is_ok = False
                print('fedex:::',isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujian,remark)
            else:
                isok_ = None
                self.mysql_one(isok_, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujian,
                               remark,
                               mysql_name='load_fedex')
                print('fedex:::',isok_, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujian,remark)
        self.fedex_run1(fedex_load, number, warehouse_sku, zhujians, remark, list_fedex)

    def fedex_run1(self, fedex_load, number, warehouse_sku, zhujians, remark, list_fedex):
        url = 'https://www.fedex.com/trackingCal/track'
        headers = {
            'Host': 'www.fedex.com',
            'Connection': 'keep-alive',
            # 'Content-Length': '459',
            'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
            'Accept': '*/*',
            'ADRUM': 'isAjax:true',
            'sec-ch-ua-mobile': '?0',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Origin': 'https://www.fedex.com',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Dest': 'empty',
            'Referer': 'https://www.fedex.com/zh-cn/home.html',
            'Accept-Encoding': 'gzip, deflate, br',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            # 'Cookie': 'fdx_cbid=305401236416412883752251160372821; fdx_redirect=zh-cn; isTablet=false; isMobile=false; isWireless=false; Rbt=f0; gdl-clientId=a5192140-b372-4268-a809-adbf1929f4f0; g_sref=(direct); at_check=true; _svtri=ecfb50e7-a67e-409d-8ec8-9fe70a7d53cb; AMCVS_1E22171B520E93BF0A490D44%40AdobeOrg=1; s_ecid=MCMID%7C54992833931412773701780827342782704044; s_cc=true; Nina-nina-fedex-session=%7B%22locale%22%3A%22zh_cn%22%2C%22lcstat%22%3Afalse%7D; SMIDENTITY=idV+qWJkCsdvnztPTVNdiKUjII1sBnA/UUQkhnGeCnPKBIj5QgNUBqkG8r2pgU9zjRlADcyw1UmLM7TUO66UIN5PRJnhpTBqUdEdIcvY7dfivHl5+oALxIO+RMgn3lo4ofj2KHZfcDGb0IQxeWco5VcObWOciOo8NPklIktSbNGQki+z0lySazsYvzAHXXWf1zyn/dfqwD4NDd0ayE7okv45CcjqLW0NSn3kwW8QGsGTssDIQhtiiZUCG1tHVhGCUs2SH/Hfc0aFm9eKkp5MJK8oTl+uw0Atu/kFPaL78dPveJM/MK4C2KJHQ1VYjEwapQkkM8/dKwPfCtS8jKFMib/GCO07OhJhbBhJGVbFhKhRaLF0q+4oYNEUQU+l4B5lIKuqBQ3DdLsILPdAM7ymJFTM1ClOh55q3JcgeJ+kcSgEjDM4+nib+V2pIYVScwH7mtZXowJdDgmrgPZBz6HBzjujl3sEk6cYM98xOiCAm/3sNVt4Q2q7tc0eIQaSiv0lj0dgPzr+tjtl6wejVZVVzsnknsafgBSS; g_stime=1641347636386; mbox=PC#0066215abac045968004549b45edf750.32_0#1704598260|session#a056fd3380174340b3b76e072d059358#1641355319; fdx_locale=zh_CN; setLink=%5B%5BB%5D%5D; PIM-SESSION-ID=NnrlMpgV8A6pP9Fq; siteDC=edc; AMCV_1E22171B520E93BF0A490D44%40AdobeOrg=359503849%7CMCIDTS%7C18997%7CMCMID%7C54992833931412773701780827342782704044%7CMCAAMLH-1641961234%7C11%7CMCAAMB-1641961234%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1641363634s%7CNONE%7CMCAID%7CNONE%7CvVersion%7C5.0.1; QSI_HistorySession=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641288402174%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641347639453%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620457%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620492%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641353460113%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353489994%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353490317%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750035%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750248%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493146%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493159%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513873%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513878%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627481%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627492%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435278%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435505; _abck=886CA23387E220405ABD0C026386EB2B~0~YAAQNtMuF/HyTA1+AQAAX07aKAcDnf87pUAcRv5zmjU2kQ0oXhZsjPj8XBEtQ2HRMj6Y3ArYRE6XguRUDTzuv998/pLGvbGj8/G2NGWbqdS1VyYSuojewjYahsZA4LBSDSeGd/g3nXNJVGN+jITDPXbwqSxgzZujI/hSsVryIvDzZiDLGyu9TsUt5+oeYdd1iFq48AO9kkNTSX74JtTqNYzTj1R8cYIHAJU852Hbu8uuwA/AFFPjJ5TNzgf5vCREOTlHSIT3jn/f9xqtfOsDjRLFlRxEIgXHHSGoKlmAefutQeUVFrVWbv8FFRSsOIpMNn4n8d7AbVDw/yfrvK06pWhGqOiVh4HaujMFULk9N0CdmNLZGydziWaw5qAkODTvZwEddqcKgPb24mB3GusyA/bEgq8NFSI=~-1~-1~-1; ak_bmsc=3B1B1730CEE2B3BD4A625885CA97688E~000000000000000000000000000000~YAAQNtMuF/LyTA1+AQAAX07aKA7ILM72JrXwkPz4UlwskAECbPUZrzeiBc73Y0XnTczADlyV8I7ZBNjOwOh3pycee5Eqv9CJA+/t8KTcV7Qn4K7sIG981Ue7FlNgxwqeHHBQqQ0DrXaRQD17/P178PbqSoiI1rkEZINZAPrjQq2+0pLT2P4TjdwHOGWv2Y62vrBQu9PdZgt5e2c963c56WwK/Cu/s81yaRcwJRJNVmBICBNv6O0MVRhx5EJakyJXIlmSVnGyiGewc8AFSry6T4on5ctGpjJ6NXXB5nDCFSf3uu48Y6QNeK9JTjyWFf5kVZxCKHjVX4sRKB4WAbKP7fGr0GV8ccS2wn3B70xNfTQcN5oSOY9ehdnkGH8=; bm_sz=517985989C7DCBD9291A9826FAF6116D~YAAQNtMuF/PyTA1+AQAAX07aKA6SuAtRC2A/7/bY+fClRzv5STq31ykGHSXbXGXd1fzIx8ljWb1wQsGD/SBsppBR//Zu0qOk0ipd5atx+JQ7uuheWCSezVzwKvIKBZQ1izhMHX+qdy/NdJmao/po9c3euMVOQYZAV7Lpyp2TVllMIeWstzKyKYlJ1YGmp30E0LNcQL7VAVePSGcN8YhBDukINN2gKLgqzHgmojygkofehh6+XsYt33TyG34EUv5YxbQgkSyHg1/lFTAzDw2hHMvS3TU8CXLOC7iqHKtaW7GALQ==~4339250~4535620; s_sess=%20setLink%3D%3B%20s_ppv%3Dfedex%252Fhero%25257Ctrack%252C88%252C47%252C2536%3B%20SC_LINKS%3Dfedex%252Ftrk-detailpage-managedelivery%255E%255E%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255Efedex%252Ftrk-detailpage-managedelivery%2520%257C%2520%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255E%3B; s_pers=%20s_vnum%3D1641398399999%2526vn%253D4%7C1641398399999%3B%20gpv_pageName%3Dfedex%252Ftrk-detailpage-managedelivery%7C1641364733138%3B%20s_invisit%3Dtrue%7C1641364733147%3B; s_sq=fedexglbl%3D%2526c.%2526a.%2526activitymap.%2526page%253Dfedex%25252Ftrk-detailpage-managedelivery%2526link%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526region%253Dcontainer%2526pageIDType%253D1%2526.activitymap%2526.a%2526.c%2526pid%253Dfedex%25252Ftrk-detailpage-managedelivery%2526pidt%253D1%2526oid%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526oidt%253D3%2526ot%253DSUBMIT; ADRUM=s=1641362944203&r=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3F476261820; xacc=CN; aemserver=PROD-P-dotcom-c0016056.prod.cloud.fedex.com; bm_mi=B8EFA7EDF504E14BEE716B87C33A72DB~6UYWZe8ZUe26CWEs8kvvIA7nSLBKORtdDvJCO4E3lMBNZdFCPDyVZ7HGBHJwqEEOrA+cMACq381mNxpNIyljJF+9c9yJiKYrkyHY7ENUjXPP1W6KFnyInYSCHS1bK002EXXUSVn3Vehau4qasIMjCfd5+qb+v7wJT1usYckYSWAnPTX09KdQAkVcZ88kiY91TdXtpe+8uMKEsLX+jRNvWsFdXgUjDlSLLVhw54T0x4ESgvunRyWpkxN2vyF6lmPpR6MYO5rw5fYlJV8qU8jkVmEd78RfzHEudi+FOxOvFUeJJbzizTU94g2TU2UZ5xnb; bm_sv=4D3E7302F82B4D249F1ADB99FB5C8029~OCgNA7VPxKgyF4fZtN9KLCu9cVEab2s+XJkyzoHuBV2QJB0LcXwRZchnjut5jaII4Ork5iPqpfawAp4vBKsLtQcofhgy0Nbh+VRekLhxpf+X8/r8KtNdM01iE7720huo0nftWA74rbz0ccdLsA4GdmsOpm5+S1dBsA3/mM1DMJk='.format(j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j)
        }
        parm1 = {
            'action': 'getAssociatedShipments',
            'data': json.dumps({"AssociatedShipmentRequest": {"appDeviceType": "DESKTOP", "appType": "WTRK",
                                                              "processingParameters": {}, "uniqueKey": "",
                                                              "masterTrackingNumberInfo": {"associatedType": "MPS",
                                                                                           "trackingNumberInfo": {
                                                                                               "trackingCarrier": "",
                                                                                               "trackingNumber": "{}".format(
                                                                                                   fedex_load),
                                                                                               "trackingQualifier": "{}".format(
                                                                                                   number)}}}}),
            'format': 'json',
            'locale': 'zh_CN',
            'version': '1',

        }

        res1 = requests.post(url, headers=headers, data=parm1, verify=False, timeout=10).json()
        for i in res1['AssociatedShipmentsResponse']['associatedShipmentList']:  # [1:]
            track = i['trackingNbr']
            if track not in list_fedex:
                self.fedex_run2(track, warehouse_sku, zhujians, remark)

    def fedex_run2(self, track, warehouse_sku, zhujians, remark):
        url = 'https://www.fedex.com/trackingCal/track'
        headers = {
            'Host': 'www.fedex.com',
            'Connection': 'keep-alive',
            # 'Content-Length': '459',
            'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
            'Accept': '*/*',
            'ADRUM': 'isAjax:true',
            'sec-ch-ua-mobile': '?0',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'Origin': 'https://www.fedex.com',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Dest': 'empty',
            'Referer': 'https://www.fedex.com/zh-cn/home.html',
            'Accept-Encoding': 'gzip, deflate, br',
            'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            # 'Cookie': 'fdx_cbid=305401236416412883752251160372821; fdx_redirect=zh-cn; isTablet=false; isMobile=false; isWireless=false; Rbt=f0; gdl-clientId=a5192140-b372-4268-a809-adbf1929f4f0; g_sref=(direct); at_check=true; _svtri=ecfb50e7-a67e-409d-8ec8-9fe70a7d53cb; AMCVS_1E22171B520E93BF0A490D44%40AdobeOrg=1; s_ecid=MCMID%7C54992833931412773701780827342782704044; s_cc=true; Nina-nina-fedex-session=%7B%22locale%22%3A%22zh_cn%22%2C%22lcstat%22%3Afalse%7D; SMIDENTITY=idV+qWJkCsdvnztPTVNdiKUjII1sBnA/UUQkhnGeCnPKBIj5QgNUBqkG8r2pgU9zjRlADcyw1UmLM7TUO66UIN5PRJnhpTBqUdEdIcvY7dfivHl5+oALxIO+RMgn3lo4ofj2KHZfcDGb0IQxeWco5VcObWOciOo8NPklIktSbNGQki+z0lySazsYvzAHXXWf1zyn/dfqwD4NDd0ayE7okv45CcjqLW0NSn3kwW8QGsGTssDIQhtiiZUCG1tHVhGCUs2SH/Hfc0aFm9eKkp5MJK8oTl+uw0Atu/kFPaL78dPveJM/MK4C2KJHQ1VYjEwapQkkM8/dKwPfCtS8jKFMib/GCO07OhJhbBhJGVbFhKhRaLF0q+4oYNEUQU+l4B5lIKuqBQ3DdLsILPdAM7ymJFTM1ClOh55q3JcgeJ+kcSgEjDM4+nib+V2pIYVScwH7mtZXowJdDgmrgPZBz6HBzjujl3sEk6cYM98xOiCAm/3sNVt4Q2q7tc0eIQaSiv0lj0dgPzr+tjtl6wejVZVVzsnknsafgBSS; g_stime=1641347636386; mbox=PC#0066215abac045968004549b45edf750.32_0#1704598260|session#a056fd3380174340b3b76e072d059358#1641355319; fdx_locale=zh_CN; setLink=%5B%5BB%5D%5D; PIM-SESSION-ID=NnrlMpgV8A6pP9Fq; siteDC=edc; AMCV_1E22171B520E93BF0A490D44%40AdobeOrg=359503849%7CMCIDTS%7C18997%7CMCMID%7C54992833931412773701780827342782704044%7CMCAAMLH-1641961234%7C11%7CMCAAMB-1641961234%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1641363634s%7CNONE%7CMCAID%7CNONE%7CvVersion%7C5.0.1; QSI_HistorySession=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641288402174%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641347639453%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620457%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641349620492%7Chttps%3A%2F%2Fwww.fedex.com%2Fzh-cn%2Fhome.html~1641353460113%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353489994%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353490317%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750035%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641353750248%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493146%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355493159%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513873%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355513878%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627481%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641355627492%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435278%7Chttps%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3Ftrknbr%3D{}%26trkqual%3D2459543000~{}~FX~1641356435505; _abck=886CA23387E220405ABD0C026386EB2B~0~YAAQNtMuF/HyTA1+AQAAX07aKAcDnf87pUAcRv5zmjU2kQ0oXhZsjPj8XBEtQ2HRMj6Y3ArYRE6XguRUDTzuv998/pLGvbGj8/G2NGWbqdS1VyYSuojewjYahsZA4LBSDSeGd/g3nXNJVGN+jITDPXbwqSxgzZujI/hSsVryIvDzZiDLGyu9TsUt5+oeYdd1iFq48AO9kkNTSX74JtTqNYzTj1R8cYIHAJU852Hbu8uuwA/AFFPjJ5TNzgf5vCREOTlHSIT3jn/f9xqtfOsDjRLFlRxEIgXHHSGoKlmAefutQeUVFrVWbv8FFRSsOIpMNn4n8d7AbVDw/yfrvK06pWhGqOiVh4HaujMFULk9N0CdmNLZGydziWaw5qAkODTvZwEddqcKgPb24mB3GusyA/bEgq8NFSI=~-1~-1~-1; ak_bmsc=3B1B1730CEE2B3BD4A625885CA97688E~000000000000000000000000000000~YAAQNtMuF/LyTA1+AQAAX07aKA7ILM72JrXwkPz4UlwskAECbPUZrzeiBc73Y0XnTczADlyV8I7ZBNjOwOh3pycee5Eqv9CJA+/t8KTcV7Qn4K7sIG981Ue7FlNgxwqeHHBQqQ0DrXaRQD17/P178PbqSoiI1rkEZINZAPrjQq2+0pLT2P4TjdwHOGWv2Y62vrBQu9PdZgt5e2c963c56WwK/Cu/s81yaRcwJRJNVmBICBNv6O0MVRhx5EJakyJXIlmSVnGyiGewc8AFSry6T4on5ctGpjJ6NXXB5nDCFSf3uu48Y6QNeK9JTjyWFf5kVZxCKHjVX4sRKB4WAbKP7fGr0GV8ccS2wn3B70xNfTQcN5oSOY9ehdnkGH8=; bm_sz=517985989C7DCBD9291A9826FAF6116D~YAAQNtMuF/PyTA1+AQAAX07aKA6SuAtRC2A/7/bY+fClRzv5STq31ykGHSXbXGXd1fzIx8ljWb1wQsGD/SBsppBR//Zu0qOk0ipd5atx+JQ7uuheWCSezVzwKvIKBZQ1izhMHX+qdy/NdJmao/po9c3euMVOQYZAV7Lpyp2TVllMIeWstzKyKYlJ1YGmp30E0LNcQL7VAVePSGcN8YhBDukINN2gKLgqzHgmojygkofehh6+XsYt33TyG34EUv5YxbQgkSyHg1/lFTAzDw2hHMvS3TU8CXLOC7iqHKtaW7GALQ==~4339250~4535620; s_sess=%20setLink%3D%3B%20s_ppv%3Dfedex%252Fhero%25257Ctrack%252C88%252C47%252C2536%3B%20SC_LINKS%3Dfedex%252Ftrk-detailpage-managedelivery%255E%255E%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255Efedex%252Ftrk-detailpage-managedelivery%2520%257C%2520%25E7%25AE%25A1%25E7%2590%2586%25E9%2580%2592%25E9%2580%2581%255E%255E%3B; s_pers=%20s_vnum%3D1641398399999%2526vn%253D4%7C1641398399999%3B%20gpv_pageName%3Dfedex%252Ftrk-detailpage-managedelivery%7C1641364733138%3B%20s_invisit%3Dtrue%7C1641364733147%3B; s_sq=fedexglbl%3D%2526c.%2526a.%2526activitymap.%2526page%253Dfedex%25252Ftrk-detailpage-managedelivery%2526link%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526region%253Dcontainer%2526pageIDType%253D1%2526.activitymap%2526.a%2526.c%2526pid%253Dfedex%25252Ftrk-detailpage-managedelivery%2526pidt%253D1%2526oid%253D%2525E7%2525AE%2525A1%2525E7%252590%252586%2525E9%252580%252592%2525E9%252580%252581%2526oidt%253D3%2526ot%253DSUBMIT; ADRUM=s=1641362944203&r=https%3A%2F%2Fwww.fedex.com%2Ffedextrack%2F%3F476261820; xacc=CN; aemserver=PROD-P-dotcom-c0016056.prod.cloud.fedex.com; bm_mi=B8EFA7EDF504E14BEE716B87C33A72DB~6UYWZe8ZUe26CWEs8kvvIA7nSLBKORtdDvJCO4E3lMBNZdFCPDyVZ7HGBHJwqEEOrA+cMACq381mNxpNIyljJF+9c9yJiKYrkyHY7ENUjXPP1W6KFnyInYSCHS1bK002EXXUSVn3Vehau4qasIMjCfd5+qb+v7wJT1usYckYSWAnPTX09KdQAkVcZ88kiY91TdXtpe+8uMKEsLX+jRNvWsFdXgUjDlSLLVhw54T0x4ESgvunRyWpkxN2vyF6lmPpR6MYO5rw5fYlJV8qU8jkVmEd78RfzHEudi+FOxOvFUeJJbzizTU94g2TU2UZ5xnb; bm_sv=4D3E7302F82B4D249F1ADB99FB5C8029~OCgNA7VPxKgyF4fZtN9KLCu9cVEab2s+XJkyzoHuBV2QJB0LcXwRZchnjut5jaII4Ork5iPqpfawAp4vBKsLtQcofhgy0Nbh+VRekLhxpf+X8/r8KtNdM01iE7720huo0nftWA74rbz0ccdLsA4GdmsOpm5+S1dBsA3/mM1DMJk='.format(j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j,j)
        }
        parm1 = {
            'action': 'trackpackages',
            'data': json.dumps({"TrackPackagesRequest": {"appDeviceType": "DESKTOP", "appType": "WTRK",
                                                         "processingParameters": {}, "uniqueKey": "",
                                                         "supportCurrentLocation": True, "supportHTML": True,
                                                         "trackingInfoList": [{"trackNumberInfo": {
                                                             "trackingNumber": "{}".format(track),
                                                             "trackingQualifier": "",
                                                             "trackingCarrier": ""}}]}}),
            'format': 'json',
            'locale': 'zh_CN',
            'version': '1',

        }

        res1 = requests.post(url, headers=headers, data=parm1, verify=False, timeout=10).json()
        is_ok = True
        for i in res1['TrackPackagesResponse']['packageList'][0]['scanEventList']:
            times = i['date'] + i['time']
            title = i['status']
            describes = i['scanLocation']
            Tracking_number = track
            Primary_key = zhujians + str(times) + title

            if is_ok and title in ['已送达','国际货物放行 - 进口','已离开 FedEx 始发地服务站']:
                isok = self.times_(title, 'fedex', times)
                self.mysql_one(isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians,
                               remark,
                               mysql_name='load_fedex')
                is_ok = False
                print('fedex:::',isok, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians,remark)
            else:
                isok_ = None
                self.mysql_one(isok_, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians,
                               remark,
                               mysql_name='load_fedex')
                print('fedex:::',isok_, Primary_key, times, title, describes, Tracking_number, warehouse_sku, zhujians,remark)

    def ups(self, ups_load, warehouse_sku, zhujians):

        url = 'https://www.ups.com/track/api/Track/GetStatus?loc=zh_HK'
        headers = {
            'authority': 'www.ups.com',
            'method': 'POST',
            'path': '/track/api/Track/GetStatus?loc=zh_HK',
            'scheme': 'https',
            'accept': 'application/json, text/plain, */*',
            'accept-encoding': 'gzip, deflate, br',
            'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
            'content-length': '58',
            'content-type': 'application/json',
            'cookie': f'X-CSRF-TOKEN=CfDJ8Jcj9GhlwkdBikuRYzfhrpLd6d7_2EpfgajHg1rUZNqZdd1LdgI0QjS-1odUQjuSlKGzWLlrN6T2EM7U5Q1-h_Hikc0PYCAlvnbPDJSF7IdAghL-oQJfP6uJYxH_TpxfVFUPckUhHheTXWKeuFEkFV4; at_check=true; CONSENTMGR=consent:true%7Cts:{int(time.time()*1000)}; AMCVS_036784BD57A8BB277F000101%40AdobeOrg=1; s_cc=true; _gcl_au=1.1.983945321.1641288208; st_cur_page=st_track; aam_cms=segments%3D22945447%7C9626568%7C9626828; aam_uuid=54786243396233666111792538046679672005; HASSEENNOTICE=TRUE; s_vnum=1641288208%26vn%3D2; s_invisit=true; dayssincevisit_s=Less%20than%201%20day; bm_sz=753A648612141A6A32FDF89640261607~YAAQZ8U8t9lc3BR+AQAAhx+4Jw6RiqpZoCzGyfkSg2EitU0teK+KUSCzDfA59jOAnWJkX9jQ31DCLszX6NJotMMABbfFWkFxEz10GsCsSYpDq7/q131UEksppRkWZYz/qkUOYDdR6ZFmsfIvWWSoYRZm17a0Ll44VRUG8p6KKqDHGhiAR4ypB9v0kDgI5PDLrA1IppNDLhX0eDCYU7TmHD98zhtB+wKn7kT7L9wY1UYzjfMVzWPgckLLitVh+2448DgrQCjScoTE8aYhZBWbdk+p+H+ChdarlMLQ//JwkYY=~4469047~3618630; mboxEdgeCluster=32; ak_bmsc=E98A1AB992AC73C6412AB4A96545BFCF~000000000000000000000000000000~YAAQZ8U8tyld3BR+AQAAwCS4Jw7YSTPlifYKTL5fTRH2etGqmU0f4OA0Cf7l7mg3JjapC/loNkAH650Jd77OFJAZlGltQA8IXBFoKkYTbORaI+kZya3kc8ZOlqRtAVpBFkAk7yMFpbuzi1HQHcf3GMpkIx2a40bW39037fSjbhZvRftRneGkA9idrnFZVh3tc5ZnmePGNyytMyOG325cKS2v+fz8ZgKmYYpbkh1UWKGscrR4xkaMb0FT531hhNDRHUJvsdxzVh97nspqRWxevuHapTbXhkxi592qgTIQJSDhohO7sUpvWBiShCc8+EsaKDKy+mQabfwZBRavEFSnDxJjuqF9K3y159hCWvR/T97YKnrLNcMgfDhOxvPFQPPSBrThXJBT93sHHR+eGirDmTnOhPXCGgOcQyezwGDSqBSXgZV+ETdr/YgDHi85/kc7d2y4X1Uyi8Su7si3kyBXwQZwZkjnF7auNurNS5auVanIgxC5hsgN2YQ=; AMCV_036784BD57A8BB277F000101%40AdobeOrg=-1124106680%7CMCIDTS%7C18997%7CMCMID%7C55216696863761628391749451949285559553%7CMCAAMLH-1641948687%7C11%7CMCAAMB-1641948687%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1641351087s%7CNONE%7CMCCIDH%7C2111192083%7CvVersion%7C5.2.0; ups_language_preference=en_US; sharedsession=a0539fcd-a098-4775-a210-dd36b640161d:w; X-XSRF-TOKEN-ST=CfDJ8Jcj9GhlwkdBikuRYzfhrpIR_U6uCs7mVZuUDQyQxmOKoGcWSzavemYf-TclpDT7cIt8TWYU3W79qj0SFLpxl52i-U5ZE7jewsTxSpOh095ELOdrM8ruQ5wjMVn_g_QSlcmAuiKKCLkIa-yV1l70Hwk; PIM-SESSION-ID=VY7G9k0oEX4hJ8T9; mbox=PC#b6a27b43fde54e70ae0b0b64f1d18095.32_0#1704588727|session#c5fa41c8d9ab40b28adc4e79b621ac3c#1641345746; _abck=63AB01564BFC3D6A0514E0B7098E288B~0~YAAQZsU8t8JQz799AQAAd5K7JwcUnnR07mqTpH9tM/9JuE0/fpF56k0+1cWWFPJFwHIbaT31keXw+0x3f7lKkSHdDYjlRzftr0Bm9jOKiVCuVo12CWYNP/a0J7OmJ28dbELqGYfJ4CWzYEOtGSQonM+EiH2hwgU1b1bXREnjxO4b7Ep4Y9A6ge1KooDpkhhYlMhEpS5ImJ+M67ReSkanCLKPqGsZuOm/OFRi1Je9dD+ikfYnZNodSWkf63zsJVdNkS1uwOYZ1i8EiqJSckdSV04hsLbsDyQSj3SgWbb9QeOJZoxdrfivzDt4kiVmziRvHo02ZFjOsHZ5Tjx4HtGavmZiz0QH3a6kUQzFEGpwDTqdx33IE0ZR4RDUw6sOD+3q6TK/MPNbdDBk7WQrO7FSsy6aX7fx~-1~-1~-1; utag_main=v_id:017e246687bc00126c9d1562327703073005906b00bd0$_sn:2$_se:6$_ss:0$_st:{int(time.time()*1000)}$vapi_domain:ups.com$ses_id:{int(time.time()*1000)}%3Bexp-session$_pn:2%3Bexp-session$_prevpage:ups%3Ahk%3Azh%3Atrack%3Bexp-{int(time.time()*1000)}$_prevpageid:tracking%2FtrackWeb%2Ftra(3det).html%3Bexp-{int(time.time()*1000)}; JSESSIONID=F39F2B4D825593C43CA7D1B67652C886; RT="z=1&dm=ups.com&si=b5824023-1117-491a-b068-3e58ad647000&ss=ky0trqja&sl=5&tt=1al4&bcn=%2F%2F684d0d48.akstat.io%2F&ld=9jof"; s_nr=1641344335440-Repeat; dayssincevisit={int(time.time()*1000)}',
            'origin': 'https://www.ups.com',
            'referer': 'https://www.ups.com/track?loc=zh_HK&tracknum={}&requester=WT/'.format(ups_load),
            'sec-ch-ua': '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"',
            'sec-ch-ua-mobile': '?0',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
            'x-xsrf-token': 'CfDJ8Jcj9GhlwkdBikuRYzfhrpIR_U6uCs7mVZuUDQyQxmOKoGcWSzavemYf-TclpDT7cIt8TWYU3W79qj0SFLpxl52i-U5ZE7jewsTxSpOh095ELOdrM8ruQ5wjMVn_g_QSlcmAuiKKCLkIa-yV1l70Hwk'
        }

        parm = {
            "Locale": "zh_HK",
            "TrackingNumber": ["{}".format(ups_load)]
        }

        res = requests.post(url, headers=headers, json=parm, timeout=10).json()
        for i in res["trackDetails"][0]["shipmentProgressActivities"]:
            times = i['date'] + ' '+ i['time']
            title =i['activityScan']
            describes = i['location']
            Tracking_number = ups_load
            remark = 'True'
            datatime_time = res["trackDetails"][0]['deliveredDate'] + ' '+res["trackDetails"][0]['deliveredTime']
            deliveredDate = datetime.datetime.strptime(datatime_time, '%Y/%m/%d %H:%M')

            if title == '' and describes =='' and times == '':
                remark = '无数据'
            Primary_key = zhujians + str(times) + title
            self.mysql_one(deliveredDate, Primary_key, times, title, describes, Tracking_number, warehouse_sku,
                           zhujians, remark,
                           mysql_name='load_ups')
            print('ups:::',deliveredDate, Primary_key, times, title, describes, Tracking_number, warehouse_sku,zhujians, remark)

    def times_(self, datas, datas_, datatime_time):  # datas物流title，datas_物流平台，datatime_time节点时间

        if datas_ == 'jiufang':
            datatime_time = datetime.datetime.strptime(datatime_time, '%Y-%m-%d %H:%M:%S')
            if '已提取' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=2)
                return '{}'.format(datatime_)
            elif '已到仓' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=4)
                return '{}'.format(datatime_)
            elif '已清关' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=6)
                return '{}'.format(datatime_)
            elif '已到港' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=7)
                return '{}'.format(datatime_)
            elif '已离港' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=9)
                return '{}'.format(datatime_)
            elif '已放行' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=10)
                return '{}'.format(datatime_)
            elif '已出库' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=11)
                return '{}'.format(datatime_)
            else:
                return None
        elif datas_ == 'dhl':
            datatime_time = datatime_time.replace('T',' ')
            datatime_time = datetime.datetime.strptime(datatime_time, '%Y-%m-%d %H:%M:%S')
            if '快件已完成清關手續並從海關放行' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=5)
                return '{}'.format(datatime_)
            elif '貨件已離開DHL設施 HONG KONG - HONG KONG SAR, CHINA' in datas or '貨件已離開DHL設施 GUANGZHOU - CHINA MAINLAND' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=7)
                return '{}'.format(datatime_)
            else:
                return None

        elif datas_ == 'fedex':
            datatime_time = datetime.datetime.strptime(datatime_time, '%Y-%m-%d %H:%M:%S')
            if '国际货物放行 - 进口' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=5)
                return '{}'.format(datatime_)
            elif '已离开 FedEx 始发地服务站' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=7)
                return '{}'.format(datatime_)
            else:
                return None
        elif datas_ == 'aaf':
            datatime_time = datetime.datetime.strptime(datatime_time, '%Y-%m-%d %H:%M:%S')
            if '货物已交付' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=4)
                return '{}'.format(datatime_)
            elif '已清关放行' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=6)
                return '{}'.format(datatime_)
            elif '航班已抵达' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=7)
                return '{}'.format(datatime_)
            elif '航班已起飞' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=9)
                return '{}'.format(datatime_)
            elif '已发出' in datas:
                datatime_ = datatime_time + datetime.timedelta(days=10)
                return '{}'.format(datatime_)
            else:
                return None


if __name__ == '__main__':
    # screening_load是该文件的主函数
    run = Load()

    # run.return_mysql()
    run.screening_load()
